package com.ruoyi.epidemic.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import com.ruoyi.epidemic.mapper.TbHistoryMapper;
import com.ruoyi.epidemic.domain.TbHistory;
import com.ruoyi.epidemic.service.ITbHistoryService;

import javax.annotation.Resource;

/**
 * 历史记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-22
 */
@Service
public class TbHistoryServiceImpl implements ITbHistoryService 
{
    @Resource
    private TbHistoryMapper tbHistoryMapper;

    /**
     * 查询历史记录
     * 
     * @param id 历史记录主键
     * @return 历史记录
     */
    @Override
    public TbHistory selectTbHistoryById(Long id)
    {
        return tbHistoryMapper.selectTbHistoryById(id);
    }

    /**
     * 查询历史记录列表
     * 
     * @param tbHistory 历史记录
     * @return 历史记录
     */
    @Override
    public List<TbHistory> selectTbHistoryList(TbHistory tbHistory)
    {
        return tbHistoryMapper.selectTbHistoryList(tbHistory);
    }

    /**
     * 新增历史记录
     * 
     * @param tbHistory 历史记录
     * @return 结果
     */
    @Override
    public int insertTbHistory(TbHistory tbHistory)
    {
        return tbHistoryMapper.insertTbHistory(tbHistory);
    }

    /**
     * 修改历史记录
     * 
     * @param tbHistory 历史记录
     * @return 结果
     */
    @Override
    public int updateTbHistory(TbHistory tbHistory)
    {
        return tbHistoryMapper.updateTbHistory(tbHistory);
    }

    /**
     * 批量删除历史记录
     * 
     * @param ids 需要删除的历史记录主键
     * @return 结果
     */
    @Override
    public int deleteTbHistoryByIds(Long[] ids)
    {
        return tbHistoryMapper.deleteTbHistoryByIds(ids);
    }

    /**
     * 删除历史记录信息
     * 
     * @param id 历史记录主键
     * @return 结果
     */
    @Override
    public int deleteTbHistoryById(Long id)
    {
        return tbHistoryMapper.deleteTbHistoryById(id);
    }

    @Override
    public TbHistory selectNewData() {
        QueryWrapper<TbHistory> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_date");
        wrapper.last("limit 1");
        return tbHistoryMapper.selectOne(wrapper);
    }

    @Override
    public AjaxResult countDay() {
        QueryWrapper<TbHistory> tbHistoryQueryWrapper = new QueryWrapper<>();
        tbHistoryQueryWrapper.last("limit 5");
        List<TbHistory> tbHistories = tbHistoryMapper.selectList(tbHistoryQueryWrapper);
        return AjaxResult.success(tbHistories);
    }
}
